package com.wanmait.wanmarecruit.companiesController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.ApplyPosition;
import com.wanmait.wanmarecruit.entity.Notice;
import com.wanmait.wanmarecruit.entity.Recruiter;
import com.wanmait.wanmarecruit.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("web")
public class CompaniesCandidatesController {

    @Resource
    private ApplyPositionService applyPositionService;
    @Resource
    private PositionTypeSecondService positionTypeSecondService;
    @Resource
    private WorkExperienceTypeService workExperienceTypeService;
    @Resource
    private EducationService educationService;
    @Resource
    private ProvinceService provinceService;
    @Resource
    private UserService userService;
    @Resource
    private JobStatusService jobStatusService;
    @Resource
    private TechnologyService technologyService;
    @Resource
    private WorkExperienceService workExperienceService;
    @Resource
    private PositionTypeService positionTypeService;
    @Resource
    private EducationExperienceService educationExperienceService;
    @Resource
    private StudentCadreExperienceService studentCadreExperienceService;
    @Resource
    private HonorsWonService honorsWonService;
    @Resource
    private JobOrientationService jobOrientationService;
    @Resource
    private CompanyNatureService companyNatureService;
    @Resource
    private CompanySizeService companySizeService;
    @Resource
    private CompanyService companyService;
    @Resource
    private SalaryService salaryService;
    @Resource
    private WelfareService welfareService;
    @Resource
    private IntroductionTabService introductionTabService;
    @Resource
    private NoticeService noticeService;


    //去公司个人主页审核求职者页面（张佳炜）
    @RequestMapping("/companies/companiesHomePageCandidates")
    public void gocompaniesHomePageCandidates()
    {

    }
    //初始化求职者个人审核页面（张佳炜）
    @RequestMapping("/companies/companiesHomePageCandidatesData")
    @ModelAttribute("applyPositionPageInfo")
    public PageInfo<ApplyPosition> companiesHomePageCandidatesData(HttpSession session, Integer pageNum, String keyword)
    {
        Integer companyId = ((Recruiter)session.getAttribute("hr")).getCompanyId();
        if (pageNum==0)
        {
            pageNum=1;
        }
        Integer pageSize = 5;
        return applyPositionService.selectAllApplyPostitonByCompanyId(pageNum,pageSize,companyId,keyword);
    }
    //通过applyPositionIds修改求职者面试进度（张佳炜）
    @RequestMapping("/companies/companiesHomePageCandidates/updateApplyStatus")
    @ResponseBody
    public void updateApplyPositionByApplyPositionIds(String applyPositionIds,Integer applyStatus,HttpSession session)
    {
        ApplyPosition applyPosition = applyPositionService.getById(applyPositionIds);
        Notice notice = new Notice();
        notice.setUserId(applyPosition.getUserId());
        Integer companyId = ((Recruiter)session.getAttribute("hr")).getCompanyId();
        notice.setCompanyId(companyId);
        if (applyStatus==2) {
            notice.setNoticeModeId(3);
        }
        else
        {
            notice.setNoticeModeId(5);
        }
        noticeService.save(notice);
        applyPositionService.updateApplyStausByApplyPositionIds(applyPositionIds,applyStatus);
    }
    //通过applyPositionIds或applyPositionId删除求职者面试请求（张佳炜）
    @RequestMapping("/companies/companiesHomePageCandidates/deleteApplyPosition")
    @ResponseBody
    public void deleteApplyPositionByApplyPositionIdsOrId(String applyPositionIds)
    {
        applyPositionService.deleteSelectByApplyPositionIds(applyPositionIds);
    }
    //通过applyPositionIds假删除求职者面试申请（张佳炜）
    @RequestMapping("/companies/comaniesHomePageCandidates/enableApplyPosition")
    @ResponseBody
    public void enableApplyPositionByApplyPositionIdsOrId(String applyPositionIds)
    {
        applyPositionService.updateApplyPositionEnableByApplyPositionIds(applyPositionIds);
    }
    @RequestMapping("/companies/companiesHomePageCandidatesPositionData")
    public ModelAndView seeUserMessage(Integer userId,HttpSession session)
    {
        Integer companyId = ((Recruiter)session.getAttribute("hr")).getCompanyId();
        Notice notice = new Notice();
        notice.setNoticeModeId(1);
        notice.setCompanyId(companyId);
        notice.setUserId(userId);
        noticeService.save(notice);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user",userService.getById(userId));
        modelAndView.addObject("provinces",provinceService.getProvincesBySort());
        modelAndView.addObject("jobStatuses",jobStatusService.list());
        modelAndView.addObject("technologies",technologyService.getTecByUser(userId));
        modelAndView.addObject("workExperiences",workExperienceService.getWorkExperienceByUser(userId));
        modelAndView.addObject("positionTypes",positionTypeService.list());
        modelAndView.addObject("educationExperiences",educationExperienceService.getEducationByUser(userId));
        modelAndView.addObject("studentCadreExperiences",studentCadreExperienceService.getCadreByUserId(userId));
        modelAndView.addObject("honorsWons",honorsWonService.getHonorsByUserId(userId));
        modelAndView.addObject("jobOrientations",jobOrientationService.getJobOrientationByUserId(userId));
        modelAndView.addObject("salaries",salaryService.list());
        return modelAndView;
    }
}
